package com.yunxi.poc.starbucks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunxi.poc.starbucks.entity.TStoreCapacity;
import com.yunxi.poc.starbucks.mapper.TStoreCapacityMapper;
import com.yunxi.poc.starbucks.service.ITStoreCapacityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author shiyuan.xlc
 * @since 2021-08-12
 */
@Service
public class TStoreCapacityServiceImpl extends ServiceImpl<TStoreCapacityMapper, TStoreCapacity> implements ITStoreCapacityService {

    private final static Logger logger = LoggerFactory.getLogger(TStoreCapacityServiceImpl.class);

    @Override
    public double calculateSales(List<Integer> storeIds, LocalDate startAt, LocalDate endAt) {
        // get sales
        QueryWrapper<TStoreCapacity> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("store_id", storeIds);
        queryWrapper.ge("business_day", startAt);
        queryWrapper.lt("business_day", endAt);
        Double sales = this.getBaseMapper().sumSales(queryWrapper);

        return Optional.ofNullable(sales).orElse(0D);
    }
}
